FUNCTION_BLOCK LCB_SpeedToUnit
TITLE = 'LCB_SpeedToUnit'
//
// This FB uses the transmitted machine parameters and converts a speed value
// defined in the internal unit [rpm] into a speed value in the real unit of the machine.
// Versionshistory:
// 1.0 Ersterstellung E.Dittmann

VERSION : '1.0'
AUTHOR  : 'Lenze'
FAMILY  : 'LCB'
NAME : 'SpeToUni'
KNOW_HOW_PROTECT

VAR_INPUT
    AxisData                : BLOCK_DB;                             
    diSpeedIn_s             : DINT;                                 // Speed in rpm
END_VAR

VAR_OUTPUT
    rSpeedOutUnits          : REAL;                                 // Speed in units
    xLimit                  : BOOL;                                 // Limiterror   
END_VAR

VAR
    dwTemp                  :DWORD;
    rTemp                   :REAL;
 
END_VAR

        
BEGIN
    dwTemp              :=AxisData.dd80;   // AxisData.rSpeedToUnits
    rTemp               :=DWORD_TO_REAL(dwTemp);
    rSpeedOutUnits      :=DINT_TO_REAL(diSpeedIn_s) *  rTemp;
    IF  (rSpeedOutUnits >= 2147483647.0)  THEN
        xLimit := TRUE;
        rSpeedOutUnits := 2147483647;
    ELSIF  (rSpeedOutUnits <= -2147483647.0) THEN
        xLimit := TRUE;
        rSpeedOutUnits := -2147483647;
    ELSE
        xLimit := FALSE;
    END_IF;

END_FUNCTION_BLOCK


